<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { PageResponseData } from '../base/apis/common'
import { ViewData, apiList } from '../base/apis/user/index'

const router = useRouter()

interface UserTableData extends PageResponseData<ViewData> {}

const tableData = ref<UserTableData>({
  list: [],
  count: 0,
  pages: 0,
  size: 0,
  page: 0
})

// 获取用户列表
async function listTable() {
  try {
    const res = await apiList({
      page: 1,
      size: 10,
      sort: 'id',
      dire: 'asc',
      searchField: '',
      searchContent: ''
    });
    if (res.code === 0) {
      tableData.value = res.data;
      console.log('用户列表获取成功:', res.data);
    } else {
      console.error('获取用户列表失败:', res.message);
    }
  } catch (error) {
    console.error('获取用户列表出错:', error);
  }
}

// 页面加载时获取用户列表
listTable()

// Hero section data
const heroData = {
  title: 'Seamless Payment Solutions for Modern Businesses',
  subtitle: 'Secure, reliable and developer-friendly payment processing platform built for growth.',
  ctaPrimary: {
    text: 'Get Started',
    action: () => router.push('/services')
  },
  ctaSecondary: {
    text: 'View Documentation',
    action: () => router.push('/documentation')
  }
}

// Features data
const features = [
  {
    icon: '🔒',
    title: 'Secure Transactions',
    description: 'Industry-leading security protocols with advanced fraud detection and prevention.'
  },
  {
    icon: '🌐',
    title: 'Global Coverage',
    description: 'Accept payments in 135+ currencies with localized payment methods in over 50 countries.'
  },
  {
    icon: '⚡',
    title: 'Lightning Fast',
    description: 'High-performance infrastructure with 99.99% uptime and sub-second response times.'
  },
  {
    icon: '🛠️',
    title: 'Developer Friendly',
    description: 'Comprehensive APIs, SDKs, and detailed documentation for easy integration.'
  }
]

// Stats data
const stats = [
  { value: '99.99%', label: 'Uptime' },
  { value: '50+', label: 'Countries' },
  { value: '2.5M+', label: 'Transactions Daily' },
  { value: '10,000+', label: 'Business Partners' }
]

// Services data
const services = [
  {
    title: 'Payment Gateway',
    description: 'Process credit cards, digital wallets, and alternative payment methods with our unified platform.',
    action: 'Learn More',
    icon: '💳'
  },
  {
    title: 'Subscription Billing',
    description: 'Flexible subscription management with automated recurring billing, invoicing, and revenue recovery.',
    action: 'Learn More',
    icon: '🔄'
  },
  {
    title: 'Fraud Protection',
    description: 'Advanced AI-powered fraud detection protecting your business and customers from fraudulent transactions.',
    action: 'Learn More',
    icon: '🛡️'
  },
  {
    title: 'Global Payments',
    description: 'Accept payments in multiple currencies with automatic currency conversion and competitive exchange rates.',
    action: 'Learn More',
    icon: '🌎'
  }
]

// Testimonials data
const testimonials = [
  {
    quote: "PayFlow has transformed our payment processing. Integration was seamless, and we've seen a 15% increase in checkout conversions.",
    author: 'Sarah Johnson',
    company: 'E-Commerce Director, FashionRetail'
  },
  {
    quote: "The subscription management features have eliminated our billing headaches and reduced churn by 8%. Customer support is top-notch.",
    author: 'Michael Chen',
    company: 'CTO, SaaS Platform'
  },
  {
    quote: "We chose PayFlow for their security features and global coverage. The fraud protection alone has saved us thousands in potential losses.",
    author: 'Emma Rodriguez',
    company: 'COO, Travel Marketplace'
  }
]

// CTA section
const ctaSection = {
  title: 'Ready to transform your payment experience?',
  description: 'Join thousands of businesses using PayFlow to power their payment infrastructure.',
  buttonText: 'Start Free Trial',
  action: () => router.push('/services')
}

// Active testimonial index for responsive carousel
const activeTestimonial = ref(0)

// Change testimonial
const changeTestimonial = (index: number) => {
  activeTestimonial.value = index
}
</script>

<template>
  <div class="home-page">
    <!-- Hero Section -->
    <section class="hero-section">
      <div class="container hero-container">
        <div class="hero-content">
          <h1 class="hero-title">{{ heroData.title }}</h1>
          <p class="hero-subtitle">{{ heroData.subtitle }}</p>
          <div class="hero-cta">
            <button class="btn btn-primary hero-btn" @click="heroData.ctaPrimary.action">
              {{ heroData.ctaPrimary.text }}
            </button>
            <button class="btn btn-outline hero-btn" @click="heroData.ctaSecondary.action">
              {{ heroData.ctaSecondary.text }}
            </button>
          </div>
        </div>
        <div class="hero-image">
          <!-- Placeholder for hero image -->
          <div class="hero-image-placeholder">
            <div class="payment-card"></div>
            <div class="payment-card card-back"></div>
            <div class="payment-circle"></div>
            <div class="payment-circle circle-small"></div>
          </div>
        </div>
      </div>
    </section>

    <!-- Stats Section -->
    <section class="stats-section">
      <div class="container">
        <div class="stats-grid">
          <div v-for="(stat, index) in stats" :key="index" class="stat-item">
            <div class="stat-value">{{ stat.value }}</div>
            <div class="stat-label">{{ stat.label }}</div>
          </div>
        </div>
      </div>
    </section>

    <!-- Features Section -->
    <section class="features-section section">
      <div class="container">
        <div class="section-header text-center">
          <h2>Why Choose PayFlow?</h2>
          <p>Our platform is designed to help businesses of all sizes process payments seamlessly.</p>
        </div>
        <div class="features-grid">
          <div v-for="(feature, index) in features" :key="index" class="feature-card">
            <div class="feature-icon">{{ feature.icon }}</div>
            <h3 class="feature-title">{{ feature.title }}</h3>
            <p class="feature-description">{{ feature.description }}</p>
          </div>
        </div>
      </div>
    </section>

    <!-- Services Section -->
    <section class="services-section section">
      <div class="container">
        <div class="section-header text-center">
          <h2>Our Payment Solutions</h2>
          <p>Comprehensive payment services to grow your business</p>
        </div>
        <div class="services-grid">
          <div v-for="(service, index) in services" :key="index" class="service-card">
            <div class="service-icon">{{ service.icon }}</div>
            <h3 class="service-title">{{ service.title }}</h3>
            <p class="service-description">{{ service.description }}</p>
            <a href="#" class="service-link">{{ service.action }} →</a>
          </div>
        </div>
      </div>
    </section>

    <!-- Testimonials Section -->
    <section class="testimonials-section section">
      <div class="container">
        <div class="section-header text-center">
          <h2>What Our Customers Say</h2>
          <p>Join thousands of satisfied businesses using our platform</p>
        </div>

        <!-- Mobile Testimonial Carousel -->
        <div class="testimonial-carousel">
          <div v-for="(testimonial, index) in testimonials" :key="index"
            :class="['testimonial-slide', { active: index === activeTestimonial }]">
            <div class="testimonial-content">
              <p class="testimonial-quote">{{ testimonial.quote }}</p>
              <div class="testimonial-author">
                <p class="author-name">{{ testimonial.author }}</p>
                <p class="author-company">{{ testimonial.company }}</p>
              </div>
            </div>
          </div>

          <!-- Carousel Navigation -->
          <div class="carousel-nav">
            <button v-for="(_, index) in testimonials" :key="index"
              :class="['carousel-dot', { active: index === activeTestimonial }]"
              @click="changeTestimonial(index)"></button>
          </div>
        </div>

        <!-- Desktop Testimonial Grid -->
        <div class="testimonials-grid">
          <div v-for="(testimonial, index) in testimonials" :key="index" class="testimonial-card">
            <p class="testimonial-quote">{{ testimonial.quote }}</p>
            <div class="testimonial-author">
              <p class="author-name">{{ testimonial.author }}</p>
              <p class="author-company">{{ testimonial.company }}</p>
            </div>
          </div>
        </div>
      </div>
    </section>

    <!-- CTA Section -->
    <section class="cta-section section">
      <div class="container">
        <div class="cta-content">
          <h2>{{ ctaSection.title }}</h2>
          <p>{{ ctaSection.description }}</p>
          <button class="btn btn-primary cta-button" @click="ctaSection.action">
            {{ ctaSection.buttonText }}
          </button>
        </div>
      </div>
    </section>
  </div>
</template>

<style scoped>
/* Hero Section */
.hero-section {
  padding: calc(var(--header-height) + var(--space-12)) 0 var(--space-16);
  background: linear-gradient(135deg, var(--primary-900), var(--primary-800));
  color: white;
  position: relative;
  overflow: hidden;
}

.hero-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-8);
}

.hero-content {
  text-align: center;
  max-width: 700px;
  z-index: 1;
}

.hero-title {
  font-size: clamp(2rem, 5vw, 3.5rem);
  margin-bottom: var(--space-4);
  background: linear-gradient(135deg, white, var(--neutral-200));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-subtitle {
  font-size: clamp(1rem, 2vw, 1.25rem);
  margin-bottom: var(--space-8);
  color: var(--neutral-200);
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.hero-cta {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  align-items: center;
}

.hero-btn {
  min-width: 180px;
}

.hero-image {
  width: 100%;
  max-width: 500px;
  aspect-ratio: 4/3;
  position: relative;
}

.hero-image-placeholder {
  width: 100%;
  height: 100%;
  position: relative;
  perspective: 1000px;
}

.payment-card {
  width: 250px;
  height: 150px;
  background: linear-gradient(135deg, var(--primary-400), var(--secondary-500));
  border-radius: 12px;
  position: absolute;
  top: 20%;
  left: 20%;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  transform: rotate(-10deg);
  transition: transform 0.5s ease;
  animation: float 6s ease-in-out infinite;
}

.payment-card.card-back {
  background: linear-gradient(135deg, var(--primary-600), var(--primary-800));
  top: 30%;
  left: 30%;
  transform: rotate(5deg);
  animation: float 6s ease-in-out infinite reverse;
  animation-delay: 1s;
}

.payment-circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-500), rgba(255, 176, 59, 0.8));
  position: absolute;
  top: 10%;
  right: 20%;
  opacity: 0.8;
  animation: float 8s ease-in-out infinite;
}

.payment-circle.circle-small {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--primary-300), rgba(99, 102, 241, 0.8));
  top: 50%;
  right: 10%;
  animation: float 7s ease-in-out infinite reverse;
  animation-delay: 1.5s;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0) rotate(-5deg);
  }

  50% {
    transform: translateY(-20px) rotate(5deg);
  }
}

/* Stats Section */
.stats-section {
  background-color: white;
  padding: var(--space-8) 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-6);
}

.stat-item {
  text-align: center;
  padding: var(--space-4);
}

.stat-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary-600);
  margin-bottom: var(--space-2);
  background: linear-gradient(135deg, var(--primary-600), var(--secondary-500));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat-label {
  font-size: 1rem;
  color: var(--neutral-600);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Features Section */
.features-section {
  background-color: var(--neutral-50);
}

.section-header {
  margin-bottom: var(--space-12);
}

.text-center {
  text-align: center;
}

.section-header p {
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
  color: var(--text-secondary);
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: var(--space-6);
}

.feature-card {
  background-color: white;
  padding: var(--space-6);
  border-radius: var(--border-radius);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
}

.feature-icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-4);
}

.feature-title {
  font-size: 1.25rem;
  margin-bottom: var(--space-3);
}

.feature-description {
  color: var(--text-secondary);
}

/* Services Section */
.services-section {
  background-color: white;
}

.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-6);
}

.service-card {
  padding: var(--space-6);
  border-radius: var(--border-radius);
  border: 1px solid var(--neutral-200);
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
  position: relative;
  overflow: hidden;
}

.service-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, var(--primary-500), var(--secondary-500));
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease;
}

.service-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05);
  border-color: transparent;
}

.service-card:hover::before {
  transform: scaleX(1);
}

.service-icon {
  font-size: 2rem;
  margin-bottom: var(--space-4);
}

.service-title {
  font-size: 1.25rem;
  margin-bottom: var(--space-3);
}

.service-description {
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

.service-link {
  color: var(--primary-600);
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: color 0.2s;
}

.service-link:hover {
  color: var(--primary-700);
}

/* Testimonials Section */
.testimonials-section {
  background-color: var(--neutral-50);
}

.testimonial-carousel {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
  overflow: hidden;
}

.testimonial-slide {
  display: none;
  animation: fadeIn 0.5s ease;
}

.testimonial-slide.active {
  display: block;
}

.testimonial-content {
  background-color: white;
  padding: var(--space-6);
  border-radius: var(--border-radius);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.testimonial-quote {
  font-size: 1.1rem;
  line-height: 1.6;
  margin-bottom: var(--space-4);
  position: relative;
  font-style: italic;
}

.testimonial-quote::before {
  content: '"';
  font-size: 3rem;
  color: var(--primary-200);
  position: absolute;
  top: -20px;
  left: -10px;
  opacity: 0.5;
  font-family: Georgia, serif;
}

.testimonial-author {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.author-name {
  font-weight: 600;
  margin: 0;
}

.author-company {
  color: var(--text-tertiary);
  font-size: 0.9rem;
  margin: 0;
}

.carousel-nav {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-6);
}

.carousel-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--neutral-300);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.3s ease;
}

.carousel-dot.active {
  background-color: var(--primary-600);
  transform: scale(1.2);
}

.testimonials-grid {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-6);
}

.testimonial-card {
  background-color: white;
  padding: var(--space-6);
  border-radius: var(--border-radius);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* CTA Section */
.cta-section {
  background: linear-gradient(135deg, var(--primary-600), var(--primary-800));
  color: white;
  text-align: center;
}

.cta-content {
  max-width: 700px;
  margin: 0 auto;
}

.cta-content h2 {
  margin-bottom: var(--space-4);
  font-size: 2rem;
}

.cta-content p {
  margin-bottom: var(--space-8);
  color: var(--neutral-200);
}

.cta-button {
  background-color: white;
  color: var(--primary-700);
  font-weight: 600;
  padding: var(--space-3) var(--space-8);
  font-size: 1.1rem;
  border: none;
}

.cta-button:hover {
  background-color: var(--neutral-100);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* Responsive */
@media (min-width: 768px) {
  .hero-container {
    flex-direction: row;
    justify-content: space-between;
    gap: var(--space-4);
  }

  .hero-content {
    text-align: left;
    flex: 1;
  }

  .hero-cta {
    flex-direction: row;
    align-items: flex-start;
  }

  .hero-image {
    flex: 1;
  }
}

@media (min-width: 1024px) {
  .testimonial-carousel {
    display: none;
  }

  .testimonials-grid {
    display: grid;
  }
}
</style>